package com.example.ytyproject.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class R {

    private Integer code;

    private String msg;

    private String isSuccess;

    private Object data;

    private Long total;

    public R(Integer code, String msg, String isSuccess, Object data) {
        this.code = code;
        this.msg = msg;
        this.isSuccess = isSuccess;
        this.data = data;
    }
    public R(Integer code, String msg, String isSuccess, Object data, Long total) {
        this.code = code;
        this.msg = msg;
        this.isSuccess = isSuccess;
        this.data = data;
        this.total = total;
    }
    public R(Integer code, String msg, String isSuccess) {
        this.code = code;
        this.msg = msg;
        this.isSuccess = isSuccess;
    }

    public static R ok(Object data) {
        return new R(200, "操作成功", "true", data);
    }

    public static R ok(Object data, Long total) {
        return new R(200, "操作成功", "true", data, total);
    }

    public static R ok() {
        return new R(200, "操作成功", "true");
    }

    public static R failed(String msg) {
        msg = StringUtils.isEmpty(msg) ? "操作失败" : msg;
        return new R(300, msg, "false");
    }
}
